/*
 ******************************
 * Object Oriented Programming in C
 *
 * Author: Laurent Deniau, Laurent.Deniau@cern.ch
 *
 * For more information, please see the paper:
 * http://home.cern.ch/ldeniau/html/oopc/oopc.html
 *
 ******************************
 */

#include <stdio.h>
#include <manager.h>

/* polymorphism example */
void print_person(t_person const* per)
{
  sendMsg(per, print);
}

int
main(void)
{
  t_person   *per = person  .new("Brown");
  t_employee *emp = employee.new("Smith", "Cars");
  t_manager  *mng = manager .new("Collins", "Trucks","PhD @ CMU",2);

  printf("\nList of persons:\n");
  print_person(per);
  print_person(super(emp,person));
  print_person(super(mng,employee.m.person));

  printf("\nSize of objects:\n");
  printf("sizeof(manager)   = %d\n", sizeof(t_manager));
  printf("sizeof(employee)  = %d\n", sizeof(t_employee));
  printf("sizeof(person)    = %d\n", sizeof(t_person));
  printf("sizeof(education) = %d\n", sizeof(t_education));

#ifdef DEBUG_OBJ
  /* Not present in C++ equivalent file */
  printf("\nCollins object description:\n");
  ooc_printObjInfo(stdout, mng);

  printf("\nDynamic cast example1:\n");
  ooc_printObjInfo(stdout, dynamic_cast(super(mng,employee.m.person), education));
  printf("\nDynamic cast example2:\n");
  ooc_printObjInfo(stdout, dynamic_cast(super(mng,education), person));

  printf("\nManager class description:\n");
  ooc_printClassInfo(stdout, mng);
#endif

  delete(per);
  delete(emp);
  delete(mng);

  DEBUG_DISPMEM(stderr);

  return EXIT_SUCCESS;
}
